import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {
    public static void main(String[] args) {
        while (true) {
            while (true) {
                String str = compareGuessAnswer();
                System.out.println(str);
                Boolean result = isWin(str);
                if (result) {
                    break;
                }
            }
            System.out.println("是否决定再玩一局游戏?Y/N");
            Scanner scanner = new Scanner(System.in);
            String yn = scanner.next();
            if (yn.equals("N")) {
                break;
            }
        }
    }

    //生成答案
    public static List generateAnswer() {
        List list = new ArrayList();
        Random r = new Random();
        for (int i = 0; i < 4; i++) {
            int number = r.nextInt(9);
            list.add(number);
        }
        return list;
    }

    public static List getPlayerInput() {
        List list = new ArrayList();
        for (int i = 0; i < 4; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入猜测的第" + (i + 1) + "个数字:");
            list.add(sc.next());
            continue;
        }
        return list;
    }

    public static String compareGuessAnswer() {
        List generateAnswerList = generateAnswer();
        System.out.println("正确结果是:" + generateAnswerList);
        List getPlayerInputList = getPlayerInput();
        String generateAnswer = "";
        String getPlayerInput = "";
        for (int i = 0; i < generateAnswerList.size(); i++) {
            generateAnswer += generateAnswerList.get(i);
        }
        for (int i = 0; i < getPlayerInputList.size(); i++) {
            getPlayerInput += getPlayerInputList.get(i);
        }
        if (generateAnswer.equals(getPlayerInput)) {
            return "猜对了";
        }
        return "猜测的结果错误；正确结果是:" + generateAnswer;
    }

    public static boolean isWin(String str) {
        if (str.equals("猜对了")) {
            return true;
        }
        return false;
    }
}
